<template>
  <t-link
    theme="primary"
    @click="handleOpenDialog('update', { ...props.row })"
  >
    重置密码
  </t-link>
  <!-- 自定义对话框 -->
  <custom-dialog ref="customDialogRef" v-slot="{ formData }" :api-map="{ update: updateTlUserPassword }" header="重置密码">
    <t-form-item label="用户账号" name="userName" :rules="[{ required: true, message: '请输入用户账号' }]">
      <t-input v-model:value="formData.userName" placeholder="请输入用户账号" clearable readonly />
    </t-form-item>
    <t-form-item label="用户昵称" name="userNick" :rules="[{ required: true, message: '请输入用户昵称' }]">
      <t-input v-model:value="formData.userNick" placeholder="请输入用户昵称" clearable readonly />
    </t-form-item>
    <t-form-item label="新密码" name="password" :rules="[{ required: true, message: '请输入新密码' }]">
      <t-input v-model:value="formData.password" placeholder="请输入新密码" clearable />
    </t-form-item>
  </custom-dialog>
</template>

<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { updateTlUserPassword } from '@/api/delivery/delivery'

import CustomDialog from '@/components/custom/dialog/index.vue';

// props
const props = defineProps({
  row: {
    type: Object,
    default: () => ({}),
  },
});
// 自定义对话框ref
const customDialogRef = useTemplateRef('customDialogRef');
// 处理打开对话框
const handleOpenDialog = (mode: 'create' | 'read' | 'update', params: Record<string, any>) => {
  customDialogRef.value.open(mode, params);
};
</script>

<style lang="less" scoped></style>
